﻿/*******************************************************************************
#                    ADMMENUBroker.cs
#  Comment:
#
#  Current Version: V1.0
#  Author: 
#
#  History List:
#  V1.0    Created by Onions@2009-8-18 20:07:18
#
#******************************************************************************/
#region Usings
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SYS.Basic;

using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;
#endregion

namespace ExpertMIS.Brokers
{
    public class ADMMENUBroker : ExpertMISBaseBroker
    {
        #region Private Methods

        private object UpdateADMMENUEntity(IEntity entity)
        {
            return SqlMap.Update("UpdateADMMENUEntity", entity);
        }

        private object InsertADMMENUEntity(IEntity entity)
        {
            return SqlMap.Insert("InsertADMMENUEntity", entity);
        }

        private object DeleteADMMENUEntity(IEntity entity)
        {
            return SqlMap.Delete("DeleteADMMENUEntity", entity);
        }

        #endregion

        #region Override Methods

        protected override IEntity ProcessGetEntity(System.Collections.Hashtable keys)
        {
            if (!keys.Contains("OID")) throw new Exception("invalid request parameters.");
            return SqlMap.QueryForObject<IEntity>("SelectADMMENUEntityByOID", keys["OID"] as string);
        }

        protected override bool ProcessSaveEntity(IEntity entity, Hashtable request)
        {
            if (entity.EntityState == EntityState.New)
            {
                InsertADMMENUEntity(entity);
                entity.EntityState = EntityState.Old;
            }
            else
            {
                UpdateADMMENUEntity(entity);
            }

            return true;
        }

        protected override IEntity ProcessNewEntity()
        {
            ADMMENUEntity entity = new ADMMENUEntity();

            // initial entity object

            return entity;
        }

        protected override bool ProcessRemoveEntity(IEntity entity, Hashtable request)
        {
            try
            {
                DeleteADMMENUEntity(entity);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region Public Method
        public IList<ADMMENUEntity> GetModuleMenus(string ModuleOID)
        {
            return SqlMap.QueryForList<ADMMENUEntity>("SelectMenusByModuleOID", ModuleOID);
        }
        #endregion
    }
}